using System;
using Ease.EaseNode.Editor.NodeView;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;

namespace Ease.TestEaseNode.Editor
{
    public class TestChartView : BaseEaseChartView
    {
        public new class UxmlFactory : UxmlFactory<TestChartView, UxmlTraits>
        {
        }

        public TestChartView() : base()
        {
            var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Ease/TestEaseNode/Editor/Test.uss");
            styleSheets.Add(styleSheet);
            //新建搜索菜单
            var menuWindowProvider = ScriptableObject.CreateInstance<CreateSearchMenuWindowProvider>();
            menuWindowProvider.OnSelectEntryHandler += OnMenuSelectEntry;
            nodeCreationRequest += context => { SearchWindow.Open(new SearchWindowContext(context.screenMousePosition), menuWindowProvider); };
        }

        public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
        {
            base.BuildContextualMenu(evt);
            evt.menu.AppendSeparator();
            evt.menu.AppendAction("gggg/类型1", (Action<DropdownMenuAction>) (a => { Debug.Log(a.name); }),
                (Func<DropdownMenuAction, DropdownMenuAction.Status>) (a => true ? DropdownMenuAction.Status.Normal : DropdownMenuAction.Status.Disabled));
            evt.menu.AppendAction("gggg/类型2", (Action<DropdownMenuAction>) (a => { Debug.Log(a.name); }),
                (Func<DropdownMenuAction, DropdownMenuAction.Status>) (a => true ? DropdownMenuAction.Status.Normal : DropdownMenuAction.Status.Disabled));

            evt.menu.AppendSeparator();
        }
    }
}